<template>
  <div class="permission-container">
    <el-card>
      <template #header>
        <div class="header">
          <el-button type="primary" @click="handleAdd">新增权限</el-button>
        </div>
      </template>
      
      <el-table
        :data="permissionList"
        row-key="id"
        :tree-props="{ children: 'children' }"
        v-loading="loading"
      >
        <el-table-column prop="name" label="权限名称" />
        <el-table-column prop="enname" label="权限标识" />
        <el-table-column prop="url" label="路由地址" />
        <el-table-column prop="type" label="类型">
          <template #default="{ row }">
            {{ row.type === 1 ? '菜单' : '按钮' }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="{ row }">
            <el-button type="primary" link @click="handleEdit(row)">编辑</el-button>
            <el-button type="danger" link @click="handleDelete(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { getPermissionTree } from '@/api/permission'
import type { Permission } from '@/types/api/permission'

const loading = ref(false)
const permissionList = ref<Permission[]>([])

onMounted(async () => {
  await loadPermissions()
})

const loadPermissions = async () => {
  loading.value = true
  try {
    const { data } = await getPermissionTree()
    permissionList.value = data
  } finally {
    loading.value = false
  }
}

// TODO: 实现新增、编辑、删除功能
</script> 